<span id="${uuid}"></span>

<div class="box_tc_s">
    <form data-id="baseForm">
        <table border="1" class="hydra-table" cellpadding="0" cellspacing="0">
            <tr>
                <td class="hydra-left"><span class="nes-tip">*</span>结构名称：</td>
                <td class="hydra-right">
                    <input type="hidden" value="${pbom.id}" data-id="id" name="id" />
                    <input type="text" data-id="pName"
                           name="pName" class="easyui-validatebox hydra-input-width"
                           data-options="required:true,validType:['length[0,20]']"
                           placeholder="结构名称.." value=""/>
                </td>
            </tr>
            <tr class="hydra-tr-bg">
                <td class="hydra-left"><span class="nes-tip">*</span>结构编码：</td>
                <td class="hydra-right"><input type="text" data-id="code"
                                               name="code" class="easyui-validatebox hydra-input-width"
                                               data-options="required:true,validType:['length[0,20]']"
                                               placeholder="结构编码.." value=""/></td>
            </tr>
            <tr>
                <td class="hydra-left"><span class="nes-tip">*</span>数量：</td>
                <td class="hydra-right">
                    <input type="text" data-id="number"
                           name="number" class="easyui-validatebox hydra-input-width"
                           data-options="required:true,validType:['length[0,20]']"
                           placeholder="数量.." value="1"/>
                </td>
            </tr>
            <tr>
                <td class="hydra-left">制造分类：</td>
                <td class="hydra-right">
                    <select data-id="bomType" name="bomType" class="easyui-validatebox hydra-input-width">
                         <c:forEach items="${bomTypes}" var="bomType">
                             <option value="${bomType.dirValue}">${bomType.dirValue}</option>
                         </c:forEach>
                    </select>
                </td>
            </tr>
            <tr class="hydra-tr-bg">
                <td class="hydra-left">备注:</td>
                <td class="hydra-right"><textarea data-id="remark"
                                                  autocomplete="off" name="remark"
                                                  class="easyui-validatebox hydra-input-width hydra-textarea"
                                                  data-options="validType:['normalChar','length[0,400]']"
                                                  placeholder="备注.."></textarea></td>
            </tr>
        </table>
    </form>
</div>
<script language="javascript">
    seajs.use("apps/easyui", function(){
        var uuid = "${uuid}";
        var page = new $.PageDomFactory(uuid);
        var pp = page.getJqDom("code");
        var cache = {};
        page.getJqDom("number").numberbox({
            min:1
        });
        page.getJqDom("bomType").combobox();
        page.getJqDom("pName").on("change", function(){
            var v = $(this).val();
            if(!pp.val().length){
                if(cache[v]){
                    pp.val(cache[v]);
                }else{
                    $.post("${pageContext.request.contextPath}/app/api/pbom/createCode", {pName:v}, function(data){
                        cache[v] = data.code;
                        pp.val(data.code);
                    }, "JSON")
                }
            }
        });
        $[uuid] = {
            pageFactory: page
        }
    });

    function add_pbom_child(win){
        if (!$["${uuid}"].pageFactory.getJqDom('baseForm').form('validate')) {
            return false;
        }
        win.wait("start", "保存中,请稍候.");
        var form = $["${uuid}"].pageFactory.getJqDom("baseForm");
        var postData = form.serializeJson();
        win.callback(true, postData);
        win.wait("end");
        win.close();
    }
</script>